#include "Timer.h"

using namespace gull::core;
using namespace std;



void
Timer::testClass()
{
    Timer t;
    t.start();
    Timer::wait(1450);
    t.stop();
    cout << t << endl;
}


Timer::Timer():
m_time(0.0),
m_timeStart(0.0),
m_timeStop(0.0)
{
}

void
Timer::start()
{
    m_timeStart = ((double)clock()/CLOCKS_PER_SEC) * 1000.0;
}

void
Timer::restart()
{
	start();
}

gullTime 
Timer::getTime() const
{
	gullTime currentTime = (((double)clock()/CLOCKS_PER_SEC) * 1000.0) - m_timeStart;
    return currentTime;
}


void
Timer::stop()
{
    m_timeStart = m_timeStop = 0;
}




void
Timer::wait(int milliseconds)
{
    gullTime start = ((double)clock()/CLOCKS_PER_SEC) * 1000.0;
    gullTime end = start + milliseconds;
    gullTime currentTime = start;
    while (currentTime < end)
        currentTime = ((double)clock()/CLOCKS_PER_SEC) * 1000.0;
}



ostream&
operator<<(ostream& o, const Timer& t)
{
    o << t.getTime() << "ms";
    return o;
}